package lion.se.lucene.index;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.index.LogByteSizeMergePolicy;
import org.apache.lucene.index.LogMergePolicy;

/**
 * @author Helin
 * @date 2011-4-4
 * 
 */
public class IndexConf {

	public synchronized static IndexWriterConfig getConf() {

		return getConf(new StandardAnalyzer());
	}

	public static IndexWriterConfig getConf(Analyzer analyzer) {

		if (analyzer == null) {
			analyzer = new StandardAnalyzer();
		}

		IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer);
		indexWriterConfig.setMaxBufferedDocs(Integer.MAX_VALUE);
		indexWriterConfig.setMaxThreadStates(20);
		indexWriterConfig.setOpenMode(OpenMode.CREATE_OR_APPEND);
		indexWriterConfig.setRAMBufferSizeMB(1024);
		indexWriterConfig.setUseCompoundFile(false);

		LogMergePolicy mergePolicy = new LogByteSizeMergePolicy();
		mergePolicy.setMergeFactor(100);
		mergePolicy.setMaxMergeDocs(Integer.MAX_VALUE);
		indexWriterConfig.setMergePolicy(mergePolicy);

		return indexWriterConfig;
	}

}
